package ec.atreasure.com.ec.launcher;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;

import java.util.ArrayList;

import ec.atreasure.com.core.app.AccountManager;
import ec.atreasure.com.core.app.IUserChecker;
import ec.atreasure.com.core.fragments.AtreasureFragment;
import ec.atreasure.com.ec.R;
import ec.atreasure.com.ec.login.LoginFragment;
import ec.atreasure.com.ui.launcher.ILauncherListener;
import ec.atreasure.com.ui.launcher.LauncherHolderCreator;
import ec.atreasure.com.ui.launcher.OnLauncherFinishTag;

/**
 * Description :启动页界面（带滚动页）
 * Created by wangjin on 2019/6/27.
 * Job number：
 * Phone ：18301070822
 * Email： 120182051@qq.com
 * Person in charge : 汪渝栋
 * Leader：
 */
public class LauncherScrollFragment extends AtreasureFragment implements OnItemClickListener {

    //滚动页面布局
    private ConvenientBanner<Integer> mConvenientBanner = null;

    private AppCompatTextView mLauncherText = null;

    //滚动页面需要展示的数据资源
    private static final ArrayList<Integer> mDatas = new ArrayList<>();

    @Override
    public Object setLayout() {
        return R.layout.launcher_scroll_fragment;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        initBanner();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    private void initBanner() {
        mConvenientBanner = findViewById(R.id.launcher_banner);
        mLauncherText = findViewById(R.id.launcher_text);

        if (mDatas.size() == 0) {
            mDatas.add(R.mipmap.launcher_01);
            mDatas.add(R.mipmap.launcher_02);
            mDatas.add(R.mipmap.launcher_03);
            mDatas.add(R.mipmap.launcher_04);
            mDatas.add(R.mipmap.launcher_05);
        }

        mConvenientBanner.setPages(new LauncherHolderCreator(), mDatas)
                .setPageIndicator(new int[]{R.drawable.dot_normal, R.drawable.dot_focus})
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .setOnItemClickListener(this)
                .setCanLoop(false);

        mLauncherText.setOnClickListener(v -> onClickLauncherText());
    }

    private void onClickLauncherText() {
        startWithPop(new LoginFragment());
    }

    @Override
    public void onItemClick(int position) {

    }
}
